pipeline {
    agent { label 'slave_agent' }
    
    stages {
        stage('准备参数') {
            steps {
                script {
                    SERVER_ADRESS="${SERVERIP}"
                }
            }
        }
        
        stage('拉取代码') {
            steps {
                checkout([$class: 'GitSCM', branches: [[name: '${BRANCH}']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'f95950e6-9c19-494a-aaff-15a64958b1ba', url: 'http://10.12.3.141/ATAP/frontend.git']]])
            }
        }
        
       	stage('安装依赖') {
            steps {
                sh 'npm install'
            }
        }
       	
        stage('构建打包') {
            steps {
                sh 'npm run build'
            }
        }
        
        stage('推送部署文件') {
            steps {
                script {
                    sh "cd ${WORKSPACE} && tar -zvcf dist.tar.gz dist && tar -zvcf docker.tar.gz docker"
                    if(SERVER_ADRESS == '10.1.5.159'){
                        echo "start copy tar.gz to 10.1.5.159"
                        sh "scp ${WORKSPACE}/dist.tar.gz atapfrontend@${SERVERIP}:/home/atapfrontend"
                        sh "scp ${WORKSPACE}/docker.tar.gz atapfrontend@${SERVERIP}:/home/atapfrontend"
                        sh "ssh atapfrontend@${SERVERIP} ./startfrontend.sh"
                    }else{
                        echo "start copy tar.gz to 10.1.5.178"
                        sh "scp ${WORKSPACE}/dist.tar.gz atapserver@${SERVERIP}:/home/atapserver"
                        sh "scp ${WORKSPACE}/docker.tar.gz atapserver@${SERVERIP}:/home/atapserver"
                        sh "ssh atapserver@${SERVERIP} ./startfrontend.sh"
                    }
                }
            }
        }
        
    }
}